package com.shihan._01_multi_thread_basic.producer_consumer;

import java.util.concurrent.TimeUnit;

/**
 * @Description 消费者
 * @Author shihan
 * @Date 2021/8/10 7:47
 * @Version 1.0
 */
public class MyConsumer implements Runnable {

    private MyQueue myQueue;

    public MyConsumer(MyQueue myQueue) {
        this.myQueue = myQueue;
    }

    @Override
    public void run() {
        while (true) {
            try {
                // 间隔 1 秒消费一次
                TimeUnit.SECONDS.sleep(1);
                String getValue = myQueue.get();
                System.out.println("消费者：" + Thread.currentThread().getName() + "消费内容：" + getValue);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
